package com.ruoyi.order.listener;

import com.ruoyi.order.domain.MesSendFactoryLog;
import com.ruoyi.order.event.ProcessDataEvent;
import com.ruoyi.order.proxy.factory.FactoryProxy;
import com.ruoyi.order.proxy.factory.req.FactoryHeader;
import com.ruoyi.order.service.IConfigService;
import com.ruoyi.order.service.IMesSendFactoryLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
@Slf4j
@Component
public class ProcessDataListener {
    @Autowired
    private FactoryProxy factoryProxy;

    @Autowired
    private IConfigService configService;
    @Autowired
    private IMesSendFactoryLogService sendFactoryLogService;

    /**
     * 插入发送日志表，通过异步定时任务捞取后发送，解耦产线操作
     * @param event
     */
    @EventListener
    public void sendProcessData2Factory(ProcessDataEvent event) {
        MesSendFactoryLog mesSendFactoryLog = new MesSendFactoryLog();
        FactoryHeader header = event.getProcessDataRequest().getHeader();
        if (header != null && header.getPartIdentifier() != null) {
            mesSendFactoryLog.setResultId(header.getResultId());
            mesSendFactoryLog.setPartNumber(header.getPartIdentifier());
            mesSendFactoryLog.setStatus("N");
            sendFactoryLogService.insertMesSendFactoryLog(mesSendFactoryLog);
        }
    }
}
